define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            var window_innerheight = window.innerHeight;
            var table_height = window_innerheight-20;
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'caiwu/billcate/index',
                    add_url: 'caiwu/billcate/add',
                    edit_url: 'caiwu/billcate/edit',
                    del_url: 'caiwu/billcate/del',
                    multi_url: '',
                    dragsort_url: '',
                    table: 'billcate',
                },
                pageSize: Config.pagesize,
                height: table_height
            });

            var table = $("#table");

            //绑定TAB事件
            $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                // var options = table.bootstrapTable(tableOptions);
                var typeStr = $(this).attr("href").replace('#','');
                var options = table.bootstrapTable('getOptions');
                options.pageNumber = 1;
                options.queryParams = function (params) {
                    // params.filter = JSON.stringify({type: typeStr});
                    params.type = typeStr;

                    return params;
                };
                table.bootstrapTable('refresh', {});
                return false;

            });

            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false,visible: false},

                        {field: 'cate_name', title: __('Name'),operate: 'like'},

                        {field: 'bianhao', title: __('Code')},


                        {field: 'update_time2', title: __('Update time'),operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);


            //必须默认触发shown.bs.tab事件
            // $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");

        },
        add: function () {
            Controller.api.bindevent();
        },

        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {


            }
        }
    };
    return Controller;
});
